﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class userManager : System.Web.UI.Page
{
    public static int flag1, flag2;


    LogicLayer logic = new LogicLayer();

    protected void Page_Load(object sender, EventArgs e)
    {

        DropDownList1.Focus();

    }


    protected void GridView_1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        string sqlstring = "delete from employee where employee.EmployID = "
            + GridView1.DataKeys[e.RowIndex].Value;

        logic.ExcuteSQLStatement(sqlstring);


        if (flag1 == 1)
        {
            sqlstring = "select employee.* from employee where employee.EmployID = " +
                 TextBox1.Text.Trim();
            DataSet ds = logic.GetDataSet(sqlstring);

            if (DropDownList1.Text.Trim() == "北京")
            {
                sqlstring = "select employee.* from employee where employee.EmployID = " +
                              TextBox1.Text.Trim() + " and employee.EmployID LIKE '1%'";
                ds = logic.GetDataSet(sqlstring);
            }
            else if (DropDownList1.Text.Trim() == "上海")
            {
                sqlstring = "select employee.* from employee where employee.EmployID = " +
                              TextBox1.Text.Trim() + " and employee.EmployID LIKE '2%'";
                ds = logic.GetDataSet(sqlstring);
            }
            else if (DropDownList1.Text.Trim() == "广州")
            {
                sqlstring = "select employee.* from employee where employee.EmployID = " +
                              TextBox1.Text.Trim() + " and employee.EmployID LIKE '3%'";
                ds = logic.GetDataSet(sqlstring);
            }


            this.GridView1.DataSource = ds;
            this.GridView1.DataKeyNames = new string[] { "EmployID" };
            this.GridView1.DataBind();
        }
        else if (flag2 == 1)
        {
            sqlstring = "select employee.* from employee where employee.EmployName = '" +
                              TextBox2.Text.Trim() + "'";

            DataSet ds = logic.GetDataSet(sqlstring);
            if (DropDownList1.Text.Trim() == "北京")
            {
                sqlstring = "select employee.* from employee where employee.EmployName = '" +
                              TextBox2.Text.Trim() + "'" + " and employee.EmployID LIKE '1%'";
                ds = logic.GetDataSet(sqlstring);
            }
            else if (DropDownList1.Text.Trim() == "上海")
            {
                sqlstring = "select employee.* from employee where employee.EmployName = '" +
                              TextBox2.Text.Trim() + "'" + " and employee.EmployID LIKE '2%'";
                ds = logic.GetDataSet(sqlstring);
            }
            else if (DropDownList1.Text.Trim() == "广州")
            {
                sqlstring = "select employee.* from employee where employee.EmployName = '" +
                              TextBox2.Text.Trim() + "'" + " and employee.EmployID LIKE '3%'";
                ds = logic.GetDataSet(sqlstring);
            }

            this.GridView1.DataSource = ds;
            this.GridView1.DataKeyNames = new string[] { "EmployID" };
            this.GridView1.DataBind();

        }

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ((LinkButton)e.Row.Cells[1].Controls[0]).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
        }






    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        flag1 = 1; flag2 = 0;
        string sqlstring = "select employee.* from employee where employee.EmployID = " +
                  TextBox1.Text.Trim();
        DataSet ds = logic.GetDataSet(sqlstring);

        if (DropDownList1.Text.Trim() == "北京")
        {
            sqlstring = "select employee.* from employee where employee.EmployID = " +
                          TextBox1.Text.Trim() + " and employee.EmployID LIKE '1%'";
            ds = logic.GetDataSet(sqlstring);
        }
        else if (DropDownList1.Text.Trim() == "上海")
        {
            sqlstring = "select employee.* from employee where employee.EmployID = " +
                          TextBox1.Text.Trim() + " and employee.EmployID LIKE '2%'";
            ds = logic.GetDataSet(sqlstring);
        }
        else if (DropDownList1.Text.Trim() == "广州")
        {
            sqlstring = "select employee.* from employee where employee.EmployID = " +
                          TextBox1.Text.Trim() + " and employee.EmployID LIKE '3%'";
            ds = logic.GetDataSet(sqlstring);
        }


        this.GridView1.DataSource = ds;
        this.GridView1.DataKeyNames = new string[] { "EmployID" };
        this.GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        flag2 = 1; flag1 = 0;
        string sqlstring = "select employee.* from employee where employee.EmployName = '" +
                          TextBox2.Text.Trim() + "'";

        DataSet ds = logic.GetDataSet(sqlstring);
        if (DropDownList1.Text.Trim() == "北京")
        {
            sqlstring = "select employee.* from employee where employee.EmployName = '" +
                          TextBox2.Text.Trim() + "'" + " and employee.EmployID LIKE '1%'";
            ds = logic.GetDataSet(sqlstring);
        }
        else if (DropDownList1.Text.Trim() == "上海")
        {
            sqlstring = "select employee.* from employee where employee.EmployName = '" +
                          TextBox2.Text.Trim() + "'" + " and employee.EmployID LIKE '2%'";
            ds = logic.GetDataSet(sqlstring);
        }
        else if (DropDownList1.Text.Trim() == "广州")
        {
            sqlstring = "select employee.* from employee where employee.EmployName = '" +
                          TextBox2.Text.Trim() + "'" + " and employee.EmployID LIKE '3%'";
            ds = logic.GetDataSet(sqlstring);
        }

        this.GridView1.DataSource = ds;
        this.GridView1.DataKeyNames = new string[] { "EmployID" };
        this.GridView1.DataBind();

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "update")
        {
            int index = Convert.ToInt32(e.CommandArgument);

            Response.Redirect("UserUpdate.aspx?employID=" + GridView1.Rows[index].Cells[2].Text.ToString());
        }
    }
}
